package addCompo.actionbar
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class XMActionBar extends MovieClip
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		public var txt 				: TextField;
		public var naviBtn 			: MovieClip;
		public var actionBarBg 		: MovieClip;
		public var titleTF 			: TextField;
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		private var textFormat 				: TextFormat;
		private var naviBtnDefaultWidth 	: Number; //Navi버튼 기본 Width 값 담아둘 변수
		private var titleTFLimitWidth		: Number; //titleTF 넓이 제한
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		/**
		 * constructor 
		 */	
		public function XMActionBar()
		{
			trace("===> ActionBar , ActionBar : " );
			super();
			
			naviBtnDefaultWidth = naviBtn.width;
			
			textFormat = new TextFormat( null , 17, 0xffffff, true );
			
			txt.defaultTextFormat = textFormat;
			txt.mouseEnabled = false;
			txt.selectable = false;
			txt.setTextFormat( textFormat );
			txt.x = naviBtn.x + 20;
			txt.y = naviBtn.y + ( naviBtn.height - txt.height )/2;
			
			titleTF.y = ( actionBarBg.height - titleTF.height )/2;
			titleTF.mouseEnabled = false;
			titleTF.selectable = false;
			
			naviBtn.addEventListener(MouseEvent.MOUSE_DOWN, onNaviBtnDown );
			naviBtn.addEventListener(MouseEvent.MOUSE_UP, onNaviBtnUp );
			naviBtn.addEventListener(MouseEvent.ROLL_OUT, onNaviBtnUp );
			
		}
		
		[Inspectable(name="NaviBtnLabel", defaultValue = "", type = String )]
		public function get NaviBtnLabel (): String
		{
			return txt.text;
		}
		public function set NaviBtnLabel ( str : String ):void
		{
			txt.text = str;
			txt.autoSize = TextFieldAutoSize.LEFT;
			naviBtn.width = txt.width + 30;
			
			if( naviBtn.width <= naviBtnDefaultWidth )		naviBtn.width = naviBtnDefaultWidth;
			
			titleTF.x = naviBtn.x + naviBtn.width + 10;
		}
		
		[Inspectable(name="Title", defaultValue = "", type = String )]
		public function get Title (): String
		{
			return titleTF.text;
		}
		public function set Title ( str : String ):void
		{
			titleTF.text = str;
			
			titleTFLimitWidth = actionBarBg.width - titleTF.x - 10;
			
			titleTF.width = titleTFLimitWidth;
			
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function onNaviBtnDown(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			if( currentTarget.currentFrame == 1 ) currentTarget.gotoAndStop(2);
		}
		
		/**
		 *
		 */
		private function onNaviBtnUp(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			if( currentTarget.currentFrame == 2 ) currentTarget.gotoAndStop(1);
		}
		
	}
}